//
//  LKBasTBC.m
//  QuickCure
//
//  Created by 胡不归是大虾 on 9/13/16.
//  Copyright © 2016 haoge. All rights reserved.
//

#import "LKBasTBC.h"
#import "NetWorkTool.h"
#import "LKBasicTypeModel.h"
static NSString* identifier = @"cell";
@interface LKBasTBC ()
@property(nonatomic,strong)NSArray* dataArray;
@property(nonatomic,strong)NSArray* desTypesArray;

@end

@implementation LKBasTBC

- (void)viewDidLoad {
    [super viewDidLoad];
    //注册cell
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:identifier];
    self.tableView.tableFooterView = [UIView new];
    //修改标题
    self.navigationItem.title = @"疾病细分";
    //请求网络数据
    [self getDataFromNet];
}
#pragma mark--请求网络数据
-(void)getDataFromNet
{
    NSDictionary* paraDict = @{@"page":@1,@"page_size":@15,@"ci1_id":@([self.desTypesArray indexOfObject:self.illnessTypeString] +1),@"keyword":@""};
    [[NetWorkTool shareManager] POST_RequestWithUrlString:@"http://iosapi.itcast.cn/searchCI3List.json.php" parmas:paraDict successBloock:^(id responseObject) {
        NSArray* tempArray = responseObject[@"data"];
        NSMutableArray* mArray = [NSMutableArray array];
        [tempArray enumerateObjectsUsingBlock:^(NSDictionary*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            [mArray addObject:[LKBasicTypeModel basicTypeModelWithDict:obj]];
            [mArray addObject:[LKBasicTypeModel yy_modelWithDictionary:obj]];

        }];
        self.dataArray =mArray;
    } failureBlock:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
#pragma mark - tableview数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    //设置cell标题
    LKBasicTypeModel* model =self.dataArray[indexPath.row];
    cell.textLabel.text =model.ci3_name;
    //设置cell右边的箭头
    UIImageView* arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"jt"]];
    cell.accessoryView = arrowImageView;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LKBasicTypeModel* model =self.dataArray[indexPath.row];
    if (_basicTypeBlock) {
        
        _basicTypeBlock(model.ci3_name);
    }
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark--重写setter方法
-(void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    [self.tableView reloadData];
}
-(void)setIllnessTypeString:(NSString *)illnessTypeString
{
    _illnessTypeString = illnessTypeString;
    _desTypesArray =@[@"肿瘤科",@"心血管科",@"血液科",@"神经科",@"骨科"];
    _dataArray = [NSArray array];
}
@end
